﻿using AppWebApi.Authorization;
using AppWebApi.Models;
using AppWebApi.Models.Form;
using AppWebApi.Services;
using AppWebApi.Utilities.SM4;
using Microsoft.AspNetCore.Mvc;
using System.Web;

namespace AppWebApi.Controllers
{
    /// <summary>
    /// 解密参数
    /// </summary>
    [ApiController]
    [Route("/api/v1/test")]
    public class TestController : ControllerBase
    {
        private readonly AppService appService;

        public TestController(AppService appService)
        {
            this.appService = appService;
        }

        [HttpPost("Sm4Crypto")]
        public object Index([FromBody]string data)
        {
            string? encData = HttpUtility.UrlDecode(Sm4Crypto.DecryptCBC(new Sm4Crypto { Data = data }));
            if (string.IsNullOrEmpty(encData))
                return null;
            return encData;
        }
 
        /// <summary>
        /// 替换核验照片（测试）
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        [HttpPost("UpdatePersonFace")]
        public async Task<ApiResult> UpdatePersonFace([FromBody] PersonFaceEditForm form)
        {
          await   appService.UpdatePersonFacePhotoAsync(form);
            return ApiResult.Success($"人员{form.IdCard}实名采集成功").Encrypt();
        }
    }
}
